home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DDialogText.cpp < prev    next >
Text File  |  1996-07-05  |  7KB  |  230 lines

  1. // DDialogText.cp
  2. // d.g.gilbert
  3.  
  4.  
  5. #include "Dvibrant.h"
  6. #include "DDialogText.h"
  7. #include "DWindow.h"
  8. #include "DApplication.h"
  9.  
  10.  
  11. //class DDialogText : public DView
  12.  
  13. extern "C" void Nlm_SetDialogTextFont (Nlm_FonT theFont);
  14. extern Nlm_FonT           gDialogTextFont;
  15. //extern Nlm_Boolean   gDialogTextMultiline;
  16.  
  17.  
  18. DDialogText::DDialogText(long id, DView* itsSuperior, Nlm_FonT itsFont) :
  19.         DView( id, NULL, kDialogText, itsSuperior),
  20.         fText(NULL), fFont(itsFont)
  21. {
  22.     if (fFont) Nlm_SetDialogTextFont(fFont);   
  23. }
  24.  
  25. DDialogText::~DDialogText()
  26. {
  27.     if (fText) Nlm_SetTextSelect(fText, NULL, NULL); // need for motif
  28. }
  29.  
  30. char* DDialogText::GetText()
  31. {
  32.     long len = this->TextLength();
  33.     if (!len) return NULL;
  34.     char *txt = (char*) MemNew(++len);
  35.     this->GetTitle( txt, len);
  36.     txt[len-1]= 0;
  37.     return txt;
  38. }
  39.  
  40. void DDialogText::SetMultilineText( Nlm_Boolean turnon)
  41. {
  42.     //gDialogTextMultiline= turnon;
  43. }
  44.  
  45. void DDialogText::selectAction()
  46. {
  47.     if (fFont) Nlm_SetDialogTextFont(fFont);   
  48.     GetWindow()->SetEditText(this);
  49. }
  50.  
  51. void DDialogText::deselectAction()
  52. {
  53.     GetWindow()->SetEditText(NULL);
  54. }
  55.     
  56.     
  57. Boolean DDialogText::IsMyAction(DTaskMaster* action) 
  58. {
  59.     switch(action->Id()) {
  60.         case DApplication::kUndo:
  61.             Message(MSG_OK,"DDialogText::Undo not ready.");
  62.             return true;
  63.         case DApplication::kCut:
  64.             this->CutText(); 
  65.             return true;
  66.         case DApplication::kCopy:
  67.             this->CopyText(); 
  68.             return true;
  69.         case DApplication::kPaste:
  70.             this->PasteText(); 
  71.             return true;
  72.         case DApplication::kClear:
  73.             this->ClearText(); 
  74.             return true;
  75.         case DApplication::kSelectAll:
  76.             this->SetSelection(0,32000); 
  77.             return true;
  78.         default:
  79.             return DView::IsMyAction(action);
  80.         }
  81. }
  82.  
  83.  
  84. extern "C" void textActionProc(Nlm_TexT item)
  85. {
  86.     DDialogText *obj= (DDialogText*) Nlm_GetObject( (Nlm_GraphiC)item);
  87.     if (obj) obj->IsMyViewAction(obj);
  88. }
  89.  
  90. extern "C" void textSelectProc(Nlm_TexT item)
  91. {
  92.     DDialogText *obj= (DDialogText*) Nlm_GetObject( (Nlm_GraphiC)item);
  93.     if (obj) obj->selectAction();
  94. }
  95.  
  96. extern "C" void textDeselectProc(Nlm_TexT item)
  97. {
  98.     DDialogText *obj= (DDialogText*) Nlm_GetObject( (Nlm_GraphiC)item);
  99.     if (obj) obj->deselectAction();
  100. }
  101.  
  102.  
  103.         
  104. //class DEditText : public DDialogText
  105.  
  106.  
  107. DEditText::DEditText(long id, DView* itsSuperior, char* defaulttext, short charwidth, Nlm_FonT font) :
  108.         DDialogText( id, itsSuperior, font) 
  109. {
  110. #ifdef WIN_MSWIN
  111.     font= Nlm_systemFont; // some odd bug in mswin requires this font for edittext
  112.     fFont= font;
  113. #endif
  114.     Nlm_SetDialogTextFont(font);  // must be prior to Nlm_DialogText() call -- should be a call param
  115.     fText= Nlm_DialogText((Nlm_WindoW)itsSuperior->GetNlmObject(), defaulttext, charwidth, textActionProc);
  116.     this->SetNlmObject(fText);    
  117.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  118. }
  119.  
  120.  
  121.  
  122. //class DHiddenText : public DDialogText
  123.  
  124. extern "C" void textTabProc(Nlm_TexT item)
  125. {
  126.     DHiddenText *obj= (DHiddenText*) Nlm_GetObject( (Nlm_GraphiC)item);
  127.     if (obj) obj->tabaction();
  128. }
  129.  
  130. DHiddenText::DHiddenText(long id, DView* itsSuperior, char* defaulttext, short charwidth, Nlm_FonT font) :
  131.         DDialogText( id, itsSuperior, font) 
  132. {
  133.     fText= Nlm_HiddenText((Nlm_WindoW)itsSuperior->GetNlmObject(), defaulttext, charwidth, textActionProc, textTabProc);
  134.     this->SetNlmObject(fText);    
  135.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  136. }
  137.         
  138.  
  139.  
  140. //class DTextLine : public DDialogText
  141.  
  142. extern "C" Nlm_TexT Nlm_TextLine(Nlm_GrouP prnt, Nlm_CharPtr dfault,
  143.                                 Nlm_Int2 charWidth, Nlm_TxtActnProc actn,
  144.                                 Nlm_TxtActnProc tabProc);
  145.                                 
  146. extern "C" void textlineTabProc(Nlm_TexT item)
  147. {
  148.     DTextLine *obj= (DTextLine*) Nlm_GetObject( (Nlm_GraphiC)item);
  149.     if (obj) obj->tabaction();
  150. }
  151.  
  152. DTextLine::DTextLine(long id, DView* itsSuperior, char* defaulttext, short charwidth, Nlm_FonT font) :
  153.         DDialogText( id, itsSuperior, font) 
  154. {
  155.     fText= Nlm_TextLine((Nlm_GrouP)itsSuperior->GetNlmObject(), defaulttext, charwidth, 
  156.                                             textActionProc, textlineTabProc);
  157.     this->SetNlmObject(fText);    
  158.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  159. }
  160.         
  161.  
  162.  
  163. //class DPasswordText : public DDialogText
  164.  
  165. DPasswordText::DPasswordText(long id, DView* itsSuperior, char* defaulttext, short charwidth, Nlm_FonT font) :
  166.         DDialogText( id, itsSuperior, font) 
  167. {
  168.     fText= Nlm_PasswordText((Nlm_WindoW)itsSuperior->GetNlmObject(), defaulttext, charwidth, textActionProc);
  169.     this->SetNlmObject(fText);    
  170.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  171. }
  172.  
  173.  
  174.  
  175. //class DDialogScrollText : public DDialogText
  176.  
  177. DDialogScrollText::DDialogScrollText(long id, DView* itsSuperior, short width, short height, Nlm_FonT font, Boolean wrap) :
  178.         DDialogText( id, itsSuperior, font) 
  179. {
  180.     fText= Nlm_ScrollText((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, font, wrap, textActionProc);
  181.     this->SetNlmObject(fText);    
  182.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  183. }
  184.  
  185.  
  186.  
  187. #if 0                             
  188. //class DTextInScroller : public DDialogText
  189. class DTextInScroller : public DDialogText
  190. {    
  191. public:
  192.     DTextInScroller(long id, DView* itsSlateView, short width, short height, 
  193.                 Nlm_FonT font, Boolean wrap);  
  194.     DTextInScroller(long id, DView* itsSuperior, short width, short height, 
  195.                 Nlm_FonT font, Boolean wrap, Nlm_BaR verticalsb, Nlm_BaR horizontalsb);
  196. };
  197.  
  198. extern "C" Nlm_TexT Nlm_TextInScroller (Nlm_GrouP prnt, Nlm_Int2 width,
  199.                                 Nlm_Int2 height, Nlm_FonT font,
  200.                                 Nlm_Boolean wrap, Nlm_TxtActnProc actn,
  201.                                 Nlm_BaR verticalsb, Nlm_BaR horizontalsb);
  202.                                 
  203. DTextInScroller::DTextInScroller(long id, DView* itsSuperior, short width, short height,
  204.      Nlm_FonT font, Boolean wrap, Nlm_BaR verticalsb, Nlm_BaR horizontalsb) :
  205.         DDialogText( id, itsSuperior, font) 
  206. {
  207.     fText= Nlm_TextInScroller((Nlm_WindoW)itsSuperior->GetNlmObject(), width, height, font, wrap, textActionProc,
  208.                                                             verticalsb, horizontalsb);
  209.     this->SetNlmObject(fText);    
  210.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  211. }
  212.  
  213. DTextInScroller::DTextInScroller(long id, DView* itsSlateView, short width, short height,
  214.                                                  Nlm_FonT font, Boolean wrap) :
  215.     DDialogText( id, itsSlateView, font)
  216. {
  217.     Nlm_BaR verticalsb, horizontalsb;
  218.     Nlm_SlatE theSlate= (Nlm_SlatE)itsSlateView->GetNlmObject();
  219.     verticalsb  = Nlm_GetSlateVScrollBar(theSlate);
  220.     horizontalsb= Nlm_GetSlateHScrollBar(theSlate);
  221.     fText= Nlm_TextInScroller((Nlm_GrouP)theSlate, width, height, font, wrap, textActionProc,
  222.                                                     verticalsb, horizontalsb);
  223.     this->SetNlmObject(fText);    
  224.     Nlm_SetTextSelect(fText, textSelectProc, textDeselectProc);
  225. }
  226.  
  227. #endif
  228.  
  229.  
  230.